﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="showbase.aspx.cs" Inherits="jnlamp.Web.lampinfo.showbase" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     <link href="../CSS/IconExtension.css" rel="stylesheet" />
    <script src="../Script/export.js"></script>
    <script src="../Script/username.js"></script>
    <script src="../Script/datetime.js"></script> 
    <script src="../Script/highcharts.js"></script>  
    <script src="../Script/exporting.js"></script>
    <script src="../Script/jnbase.js"></script>
    <script type="text/javascript">
        var uid = 0;
        var gwid = "";        
        var add = "";
        var uname = "";
        var qxchs;
        var level = 0;
        var bid = 0;       
        $(function () {           
            bid = getUrlParam("bid");            
            InitGird();
        });
        function InitGird() {
            $('#tt').datagrid({
                title: '设备运行状态', //表格标题
                url: 'GetScd.ashx', //请求数据的页面
                sortName: 'inputTime', //排序字段
                idField: '', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                height:100,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[//
                   { title: '网关号', field: 'gwid', width: 80 },
                   { title: '灯号', field: 'lampid', width: 80, sortable:true},
                   {
                       title: '状态', field: 'lampstatus', width: 60,sortable:true, formatter: function (value, row, index) {
                           //if (value=='3')
                           //    return '失联';
                           //else if (value == '2')
                           //    return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                           //else
                               return '<img src="/images/bullet_green.png" height="16" width="16" />';
                       }
                   },
                    { title: '电池板电压', field: 'dcb_v', width: 80 },
                    { title: '蓄电池电压', field: 'xdc_v', width: 80 },
                    {
                        title: '电池板电流', field: 'dcb_i', width: 80, formatter: function (value, row, index) {
                            if (value == "True")
                                return '有电流';
                            else
                                return '无电流';
                        }
                    },
                    {
                        title: '电流', field: 'scd_i', width: 60, formatter: function (value, row, index) {
                            if (value == "True")
                                return '有电流';
                            else
                                return '无电流';
                        }
                    },
                    {
                        title: '电池板状态', field: 'dcb_s', width: 80, formatter: function (value, row, index) {
                            if (value == "1")
                                return '正常';
                            else
                                return '异常或被盗';
                        }
                    },
                    {
                        title: '开闭状态', field: 'scd_s', width:60, formatter: function (value, row, index) {
                            if (value == "1")
                                return '<img src="/images/bullet_green.png" height="16" width="16" />';
                            else
                              return '<img src="/images/bullet_red.png" height="16" width="16"/>';  
                        }
                    },
                    { title: '开闭时长', field: 'scd_t', width:60 },
                    {
                        title: '是否上传数据', field: 'datetime', width:90, formatter: function (value, row, index) {
                            if (row.inputTime == "" || row.inputTime == null)
                                return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                            else
                                return '<img src="/images/bullet_green.png" height="16" width="16" />';
                        }
                    },
                    {
                        title: '上传时间', field: 'inputTime', width: 150, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日 HH:mm:ss");
                            }
                        }
                    },
                    { title: '生产厂商', field: 'mname', width: 150 },
                    {
                        title: '历史记录', field: 'a', width:80, formatter: function (value, row, index) {
                            return '<a href="#" onclick="top.addTab(\'' + row.lampid + '\',\'/lampinfo/show.aspx?gwid=' + row.gwid + '&lampid=' + row.lampid + '\', \'icon icon-magic\');">历史记录</a>';

                        }
                    }                    
                ]
                ],
                onClickRow: function (rowIndex, rowData) {
                    var dl = "";
                    if (rowData.dcb_i == "True")
                        dl = '有电流';
                    else
                        dl = '无电流';
                    var zt = "";
                    if (rowData.dcb_s == "1")
                        zt = '正常';
                    else
                        zt = '异常或被盗';

                    var scd = "";
                    if (rowData.scd_s == "1")
                        scd = "开";
                    else
                        scd = "关";
                    yjfx = "网关ID" + rowData.gwid + "灯ID" + rowData.lampid + ",在" + rowData.inputTime + ',电池板电压' + rowData.dcb_v + ',蓄电池电压' + rowData.xdc_v + ',电池板' + dl + ',电池板状态' + zt + ',杀虫灯' + scd;
                    $('#yjfx').text(yjfx);
                },
                onLoadSuccess: function (data) {
                    var info = "";
                    info = "共有灯" + data.total + "台。";
                    //var sl = [];
                    //var sh = [];
                    //var state = "";
                    //var mname = "";
                    //var slnum = 0;
                    //var shnum = 0;
                    //$.each(data.rows, function (k, v) {
                    //    state = v["lampstatus"];
                    //    if (state == '3')
                    //    {
                    //        slnum = slnum + 1;
                    //        mname = v["mname"];
                    //        if (sl[mname]) {
                    //            sl[mname] = sl[mname] + 1;
                    //        }
                    //        else {
                    //            sl[mname] = 1;
                    //        }
                    //    }
                    //    else if (state == '2') {
                    //        shnum = shnum + 1;
                    //        mname = v["mname"];
                    //        if (sh[mname]) {
                    //            sh[mname] = sh[mname] + 1;
                    //        }
                    //        else {
                    //            sh[mname] = 1;
                    //        }
                    //    }
                        
                    //});
                    //var outputsl = "";
                    //for (var key in sl) {
                    //    if (sl.hasOwnProperty(key))
                    //    if (outputsl == "") {
                    //        outputsl =key+'('+sl[key]+')';
                    //    }
                    //    else {
                    //        outputsl += "、" + key + '(' + sl[key] + ')';
                    //    }
                    //}
                    //var outputsh = "";
                    //for (var key in sh) {
                    //    if (sh.hasOwnProperty(key))
                    //    if (outputsh == "") {
                    //        outputsh = key + '(' + sh[key] + ')';
                    //    }
                    //    else {
                    //        outputsh += "、" + key + '(' + sh[key] + ')';
                    //    }
                    //}
                    //if (slnum > 0)
                    //    info = info + "失联" + slnum + "台，失联详情：" + outputsl + "。";
                    //if (shnum > 0)
                    //    info = info + "损坏" + shnum + "台，损坏详情：" + outputsh + "。";
                    $('#slxy').html(info);
                    $('#tt').datagrid("getPanel").panel('setTitle', '设备运行状态:' + info);
                },
                toolbar: "#tab_toolbar",
                queryParams: { "action": "queryb", "bid": bid },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true                
            });
        }
       
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }
        function getQueryParams(queryParams) {
            var status = $("#cc").combobox("getValue");
            queryParams.status = status;
            return queryParams;
        }
        function showAlarm() {
            $('#dlg').dialog('open').dialog('setTitle', '预警信息发送');
            InitSendUser();
            $('#mmark').val(yjfx);
        }
        function InitSendUser() {
            $('#senduser').combotree({
                url: '../userinfo/GetLinker.ashx?action=queryt',
                multiple: true,
                width: 300,
                valueField: 'id',
                textField: 'text',
                //panelHeight: 'auto'
                panelHeight: 160

            });
            $('#mmark').ckeditor();
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].setData("");

        }
        function CKupdate() {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
        }
        function sendAlarm() {
            CKupdate();
            var f = $('#myalarm');
            var uids = $('#senduser').combotree('getValues');
            var alevel = $('#alarmlevel').val();
            $.messager.progress();

            f.form('submit', {
                url: "../info/GetInfo.ashx?action=adds&uid=" + uids + "&alarmclass=",
                onSubmit: function () {
                    var isval = $(this).form('validate');
                    if (isval == false) $.messager.progress('close');
                    return isval;
                },
                success: function (result) {
                    $.messager.progress('close');
                    if (result.indexOf("T") == 0) {
                        $('#dlg').dialog('close');
                        $.messager.alert("提示", "恭喜您，信息发送成功", "info");
                    }
                    else if ((result.indexOf("F") == 0)) {
                        $.messager.alert("提示", "发送失败，请重新操作！", "info");
                        return;
                    }
                    else if ((result.indexOf("L") == 0)) {
                        $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                        top.location = '/index.aspx';
                        return;
                    }
                }
            });
        }

    </script>   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" data-options="fit:true"> 
        <div region="center" split="true" style=" overflow:auto">
                   <table id="tt">
    </table>    
                     </div>             
    <div data-options="region:'south'" style="padding:5px;background:#eee;height:130px;">
    
        <div  id="slxy" class="easyui-panel" data-options="title: '失联信息',split:true" style="height:60px;">
        灯分析：
    </div>
        <div  id="yjfx" class="easyui-panel" data-options="title: '灯分析',split:true,tools: [{ iconCls: 'icon-phone', handler: function () { showAlarm(); } }]" style="height:60px;">
        灯分析：
    </div>  
    </div>
</div> 

    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td style="padding-left: 2px">
                    <div style="padding: 2px;">  
                            状态：<select id="cc" class="easyui-combobox" style="width:100px;">   
     <option value="0">全部</option>   
                                <option value="1">正常</option>   
    <option value="3">失联</option>   
    <option value="2">不正常</option>  
      
</select>                
                           <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Export('excel', $('#tt'));">导出</a>                               
                    </div>
                </td>
            </tr>
        </table>
        
    </div> 
    
     <div id="dlg" class="easyui-dialog" style="width: 600px; height:450px; padding: 10px 20px"
                        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">
                   <form id="myalarm" method="post">
                    <div class="fite">
                        <label style="width:auto;">发送给：</label>
                        <input name="senduser" id="senduser" />
                    </div>                   
     <div class="fitem" style="clear:none;width:380px;float:left;">
        <label style="width:auto;">标题：</label>
        <input name="alarmtitle" id="alarmtitle" style="width:280px;" />
    </div>
     <div class="fitem" style="width:200px;float:left; clear:none;">
        <label style="width:auto;">预警级别：</label>
        <select id="alarmlevel" name="alarmlevel">
            <option value="普通" selected="selected">普通</option>
            <option value="一级">一级</option>
            <option value="二级">二级</option>
            <option value="三级">三级</option>
            <option value="四级">四级</option>
        </select>
    </div>
                    <div style="clear: both;"></div>
                    <div>
                        <textarea id="mmark" name="mmark" ></textarea>
                    </div>    
                </form>
                    </div>
                    <div id="dlg-buttons">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="sendAlarm()">预警信息发布</a>
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
                    </div>   
</asp:Content>
